package com.clip.action;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.clip.action.util.SessionAttributeKey;
import com.clip.entity.ClipEvent;
import com.clip.entity.User;
import com.clip.service.EventService;
import com.clip.service.SystemDateService;
import com.clip.util.Lunar;
import com.clip.util.Struts2Utils;
import com.clip.util.ToolsUtils;

@Controller
@Scope("prototype")
public class CalendarAction {
	@Autowired
	private EventService eventService;
	@Autowired
	private SystemDateService systemDateService;
	
	
	private SimpleDateFormat dateFormat=new SimpleDateFormat("MMdd");
	public static String QUERYCALENDAROWN="own";
	public static String QUERYCALENDARPRIVATE="private";
	public static String QUERYCALENDARMEMO="memo";
	public static String QUERYCALENDARSHARE="share";
	public void getDateInfo(){
		if(year==0||month==0||date==0){
			Calendar calendar=Calendar.getInstance();
			Map<String,Object> jsonMap = new HashMap<String, Object>();
			jsonMap.put("year", calendar.get(Calendar.YEAR));
			jsonMap.put("month", calendar.get(Calendar.MONTH));
			jsonMap.put("weeknum", calendar.get(Calendar.WEEK_OF_YEAR));
			jsonMap.put("maxday", calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
			jsonMap.put("dayofmonth", calendar.get(Calendar.DAY_OF_MONTH));
			Lunar lunar=new Lunar(calendar);
			String lunarmonth=lunar.getChinese(Lunar.CHINESE_MONTH);
			String lunarday=lunar.getChinese(Lunar.CHINESE_DATE);
			String lunarholidayday=lunar.getChinese(Lunar.CHINESE_TERM_OR_DATE);
			jsonMap.put("lunarmonth",lunarmonth);
			jsonMap.put("lunarday", lunarday);
			if(!lunarholidayday.equals(lunarmonth)&&!lunarholidayday.equals(lunarday))
				jsonMap.put("lunarholidayday", lunarholidayday);
			else{
				jsonMap.put("lunarholidayday","");
			}
			String jsonStr = JSONObject.fromObject(jsonMap).toString();
			Struts2Utils.renderText(jsonStr);
		}
	}
	
	public void getEventsByMonth(){
		Calendar calendar=Calendar.getInstance();
		User currentUser=(User) Struts2Utils.getSession().getAttribute(SessionAttributeKey.USER);
		if(this.year==0&&this.month==0){
			this.year=calendar.get(Calendar.YEAR);
			this.month=calendar.get(Calendar.MONTH);
		}
		Map returnmap=organizeMonthViewMapAsXml(currentUser);
		Struts2Utils.renderXml(ToolsUtils.getDOM(returnmap));
	}
	
	public void getMemoEventsByMonth(){
		Calendar calendar=Calendar.getInstance();
		User currentUser=(User) Struts2Utils.getSession().getAttribute(SessionAttributeKey.USER);
		if(this.year==0&&this.month==0){
			this.year=calendar.get(Calendar.YEAR);
			this.month=calendar.get(Calendar.MONTH);
		}
		Map returnmap=organizeMemoMonthViewMapAsXml(currentUser);
		Struts2Utils.renderXml(ToolsUtils.getDOM(returnmap));
	}
	
	public void getClipManageEventsByMonth(){
		Calendar calendar=Calendar.getInstance();
		User currentUser=(User) Struts2Utils.getSession().getAttribute(SessionAttributeKey.USER);
		if(this.year==0&&this.month==0){
			this.year=calendar.get(Calendar.YEAR);
			this.month=calendar.get(Calendar.MONTH);
		}
		Calendar now=Calendar.getInstance();
		Map returnmap=organizeClipManageViewMapAsXml(currentUser);
		returnmap.put("year", now.get(Calendar.YEAR));
		returnmap.put("month", now.get(Calendar.MONTH));
		returnmap.put("weeknum", now.get(Calendar.WEEK_OF_YEAR));
		returnmap.put("maxday", now.getActualMaximum(Calendar.DAY_OF_MONTH));
		returnmap.put("dayofmonth", now.get(Calendar.DAY_OF_MONTH));
		Struts2Utils.renderXml(ToolsUtils.getDOM(returnmap));
	}
	
	private Map organizeClipManageViewMapAsXml(User currentUser){
		Map returnMap=new LinkedHashMap();
		Calendar now=Calendar.getInstance();
		Calendar firstDateOfMonth=Calendar.getInstance();
		firstDateOfMonth.clear(Calendar.MILLISECOND);
		firstDateOfMonth.clear(Calendar.SECOND);
		firstDateOfMonth.clear(Calendar.MINUTE);
		firstDateOfMonth.set(Calendar.HOUR_OF_DAY, 0);
		firstDateOfMonth.set(Calendar.YEAR, year);
		firstDateOfMonth.set(Calendar.MONTH,month);
		firstDateOfMonth.set(Calendar.DAY_OF_MONTH, 1);
		
		Calendar startdate=(Calendar) firstDateOfMonth.clone();
		startdate.add(Calendar.DAY_OF_MONTH, Calendar.SUNDAY-startdate.get(Calendar.DAY_OF_WEEK));
		
		Calendar lastDateOfMonth=(Calendar) firstDateOfMonth.clone();
		lastDateOfMonth.set(Calendar.DAY_OF_MONTH,firstDateOfMonth.getActualMaximum(Calendar.DAY_OF_MONTH));
		
		Calendar lastDate=(Calendar) lastDateOfMonth.clone();
		lastDate.add(Calendar.DAY_OF_MONTH, Calendar.SATURDAY-lastDate.get(Calendar.DAY_OF_WEEK));
		returnMap.put("year_month value="+this.year+"_"+this.month,new HashMap());
		int holiday=0;
		while(!startdate.after(lastDate)){
			Long size=this.eventService.queryClipListTotalCount(queryby,currentUser,content,startdate);
			//long alertcount=this.eventService.getEventsByAlertDayOnlyCount(startdate, currentUser);
			int isholiday=isSysHoliday(startdate.get(Calendar.YEAR), startdate.get(Calendar.MONTH), startdate.get(Calendar.DAY_OF_MONTH));
			int weeknum=startdate.get(Calendar.DAY_OF_WEEK);
			boolean isweekend=weeknum==1||weeknum==7?true:false;
			int isThisMonth=startdate.get(Calendar.MONTH)==this.month?1:0;
			
				
			Map<String,Object> temp2=new HashMap<String,Object>();
			temp2.put("isThisMonth", ""+isThisMonth);
			temp2.put("eventsize", size);
			//temp2.put("alerteventsize", alertcount);
			temp2.put("weeknum", ""+startdate.get(Calendar.WEEK_OF_YEAR));
			temp2.put("weekofmonth", startdate.get(Calendar.WEEK_OF_MONTH));
			temp2.put("weekday", startdate.get(Calendar.DAY_OF_WEEK));
			temp2.put("lunartxt", Lunar.getLunarText(startdate));
			
			if(isweekend){
				if(isholiday==1||isholiday==-1){ //周末也是节日
					holiday=1;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}else{ //周末不休息
					holiday=0;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}
			}else{
				if(isholiday==1){ //平时但是节日
					holiday=1;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}else{ //平时也不是节日
					holiday=0;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}
			}
			startdate.add(Calendar.DAY_OF_MONTH, 1);
		}
		
		
		return returnMap;
	}
	
	private Map organizeMemoMonthViewMapAsXml(User currentUser) {
		Map returnMap=new LinkedHashMap();
		Calendar now=Calendar.getInstance();
		Calendar firstDateOfMonth=Calendar.getInstance();
		firstDateOfMonth.clear(Calendar.MILLISECOND);
		firstDateOfMonth.clear(Calendar.SECOND);
		firstDateOfMonth.clear(Calendar.MINUTE);
		firstDateOfMonth.set(Calendar.HOUR_OF_DAY, 0);
		firstDateOfMonth.set(Calendar.YEAR, year);
		firstDateOfMonth.set(Calendar.MONTH,month);
		firstDateOfMonth.set(Calendar.DAY_OF_MONTH, 1);
		
		Calendar startdate=(Calendar) firstDateOfMonth.clone();
		startdate.add(Calendar.DAY_OF_MONTH, Calendar.SUNDAY-startdate.get(Calendar.DAY_OF_WEEK));
		
		Calendar lastDateOfMonth=(Calendar) firstDateOfMonth.clone();
		lastDateOfMonth.set(Calendar.DAY_OF_MONTH,firstDateOfMonth.getActualMaximum(Calendar.DAY_OF_MONTH));
		
		Calendar lastDate=(Calendar) lastDateOfMonth.clone();
		lastDate.add(Calendar.DAY_OF_MONTH, Calendar.SATURDAY-lastDate.get(Calendar.DAY_OF_WEEK));
		returnMap.put("year_month value="+this.year+"_"+this.month,new HashMap());
		int holiday=0;
		while(!startdate.after(lastDate)){
			int size=this.eventService.countMemoEventsByDay(startdate, currentUser);
			//long alertcount=this.eventService.getEventsByAlertDayOnlyCount(startdate, currentUser);
			int isholiday=isSysHoliday(startdate.get(Calendar.YEAR), startdate.get(Calendar.MONTH), startdate.get(Calendar.DAY_OF_MONTH));
			int weeknum=startdate.get(Calendar.DAY_OF_WEEK);
			boolean isweekend=weeknum==1||weeknum==7?true:false;
			int isThisMonth=startdate.get(Calendar.MONTH)==this.month?1:0;
			
				
			Map<String,Object> temp2=new HashMap<String,Object>();
			temp2.put("isThisMonth", ""+isThisMonth);
			temp2.put("memoeventsize", size);
			//temp2.put("alerteventsize", alertcount);
			temp2.put("weeknum", ""+startdate.get(Calendar.WEEK_OF_YEAR));
			temp2.put("weekofmonth", startdate.get(Calendar.WEEK_OF_MONTH));
			temp2.put("weekday", startdate.get(Calendar.DAY_OF_WEEK));
			temp2.put("lunartxt", Lunar.getLunarText(startdate));
			
			if(isweekend){
				if(isholiday==1||isholiday==-1){ //周末也是节日
					holiday=1;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}else{ //周末不休息
					holiday=0;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}
			}else{
				if(isholiday==1){ //平时但是节日
					holiday=1;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}else{ //平时也不是节日
					holiday=0;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}
			}
			startdate.add(Calendar.DAY_OF_MONTH, 1);
		}
		
		return returnMap;
	}

	public void getAlertEventByDay(){
		Calendar calendar=Calendar.getInstance();
		calendar.clear(Calendar.MILLISECOND);
		calendar.clear(Calendar.SECOND);
		calendar.clear(Calendar.MINUTE);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, date);
		User currentUser=(User) Struts2Utils.getSession().getAttribute(SessionAttributeKey.USER);
		List list=this.eventService.getEventsByAlertDay(calendar, currentUser,true);
		Map returnMap=new LinkedHashMap();
		for (Object object : list) {
			ClipEvent clipEvent=(ClipEvent) object;
			Map<String,Object> temp2=new HashMap<String,Object>();
			temp2.put("title",clipEvent.getTitle() );
			temp2.put("starttime",clipEvent.getBegintime() );
			temp2.put("endtime",clipEvent.getEndtime() );
			temp2.put("alerttime",clipEvent.getAlerttime() );
			temp2.put("iswholeday",clipEvent.getIswholeday() );
			returnMap.put("AlertEvent eventid="+clipEvent.getId(), temp2);
		}
		Struts2Utils.renderXml(ToolsUtils.getDOM(returnMap));
	}
	
	private Map organizeMonthViewMapAsXml(User currentUser){
		Map returnMap=new LinkedHashMap();
		Calendar now=Calendar.getInstance();
		Calendar firstDateOfMonth=Calendar.getInstance();
		firstDateOfMonth.clear(Calendar.MILLISECOND);
		firstDateOfMonth.clear(Calendar.SECOND);
		firstDateOfMonth.clear(Calendar.MINUTE);
		firstDateOfMonth.set(Calendar.HOUR_OF_DAY, 0);
		firstDateOfMonth.set(Calendar.YEAR, year);
		firstDateOfMonth.set(Calendar.MONTH,month);
		firstDateOfMonth.set(Calendar.DAY_OF_MONTH, 1);
		
		Calendar startdate=(Calendar) firstDateOfMonth.clone();
		startdate.add(Calendar.DAY_OF_MONTH, Calendar.SUNDAY-startdate.get(Calendar.DAY_OF_WEEK));
		
		Calendar lastDateOfMonth=(Calendar) firstDateOfMonth.clone();
		lastDateOfMonth.set(Calendar.DAY_OF_MONTH,firstDateOfMonth.getActualMaximum(Calendar.DAY_OF_MONTH));
		
		Calendar lastDate=(Calendar) lastDateOfMonth.clone();
		lastDate.add(Calendar.DAY_OF_MONTH, Calendar.SATURDAY-lastDate.get(Calendar.DAY_OF_WEEK));
		returnMap.put("year_month value="+this.year+"_"+this.month,new HashMap());
		int holiday=0;
		while(!startdate.after(lastDate)){
			int isholiday=isSysHoliday(startdate.get(Calendar.YEAR), startdate.get(Calendar.MONTH), startdate.get(Calendar.DAY_OF_MONTH));
			int weeknum=startdate.get(Calendar.DAY_OF_WEEK);
			boolean isweekend=weeknum==1||weeknum==7?true:false;
			int isThisMonth=startdate.get(Calendar.MONTH)==this.month?1:0;
			
			Map<String,Object> temp2=new HashMap<String,Object>();
			temp2.put("isThisMonth", ""+isThisMonth);
			if(ids.length()>0){
				int size1=this.eventService.countStartedSubscribeByDay(startdate,currentUser.getId(),ids);
				int size2=this.eventService.countEndedSubscribeByDay(startdate,currentUser.getId(),ids);
				temp2.put("startsharesize", size1);
				temp2.put("endsharesize", size2);
				temp2.put("isssmonth", true);
			}else{
				temp2.put("isssmonth", false);
				if(currentUser.getUsertype()==2){
					long ownsize=this.eventService.countOwnEventsByDay(startdate,currentUser );
					if(ownsize>0)
						temp2.put("hasevent", 1);
					else
						temp2.put("hasevent", 0);
				}else{
					
					if(querymycalendar.equals(QUERYCALENDAROWN)){
	//					int ownsize=this.eventService.countOwnEventsByDay(startdate,currentUser);
	//					int alertcount=this.eventService.getEventsByAlertDayOnlyCount(startdate, currentUser);
						long newinvitessize=this.eventService.countInvitedEvents(currentUser, startdate);
						long ownsize=this.eventService.countOwnEventsByDay(startdate,currentUser );
	//					long hasacceptinvitedsize=this.eventService.countHasacceptInvitedEvents(currentUser,startdate);
						
	//					temp2.put("alerteventsize", alertcount);
						temp2.put("invitesize", newinvitessize);
						if(ownsize>0)
							temp2.put("hasevent", 1);
						else
							temp2.put("hasevent", 0);
					}else if(querymycalendar.equals(QUERYCALENDARPRIVATE)){
						int ownsize=this.eventService.countPrivateEventsByDay(startdate,currentUser);
						if(ownsize>0)
							temp2.put("hasevent", 1);
						else
							temp2.put("hasevent", 0);
					}else if(querymycalendar.equals(QUERYCALENDARMEMO)){
						int memosize=this.eventService.countMemoEventsByDay(startdate, currentUser);
						temp2.put("memosize", memosize);
					}else if(querymycalendar.equals(QUERYCALENDARSHARE)){
						long startsharesize=this.eventService.countStartedShareEventsByDay(startdate, currentUser, 1);
						temp2.put("sharesize", startsharesize);
					}
				}
			}
			temp2.put("weeknum", ""+startdate.get(Calendar.WEEK_OF_YEAR));
			temp2.put("weekofmonth", startdate.get(Calendar.WEEK_OF_MONTH));
			temp2.put("weekday", startdate.get(Calendar.DAY_OF_WEEK));
			temp2.put("lunartxt", Lunar.getLunarText(startdate));
			
			if(isweekend){
				if(isholiday==1||isholiday==-1){ //周末也是节日
					holiday=1;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}else{ //周末不休息
					holiday=0;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}
			}else{
				if(isholiday==1){ //平时但是节日
					holiday=1;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}else{ //平时也不是节日
					holiday=0;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}
			}
			startdate.add(Calendar.DAY_OF_MONTH, 1);
		}
		
		return returnMap;
	}
	
	
	public void getShareEventsByMonth(){
		Calendar calendar=Calendar.getInstance();
		User currentUser=(User) Struts2Utils.getSession().getAttribute(SessionAttributeKey.USER);
		if(this.year==0&&this.month==0){
			this.year=calendar.get(Calendar.YEAR);
			this.month=calendar.get(Calendar.MONTH);
		}
		Map returnmap=organizeShareMonthViewMapAsXml(currentUser);
		Struts2Utils.renderXml(ToolsUtils.getDOM(returnmap));
	}
	
	private Map organizeShareMonthViewMapAsXml(User currentUser) {
		Map returnMap=new LinkedHashMap();
		Calendar now=Calendar.getInstance();
		Calendar firstDateOfMonth=Calendar.getInstance();
		firstDateOfMonth.clear(Calendar.MILLISECOND);
		firstDateOfMonth.clear(Calendar.SECOND);
		firstDateOfMonth.clear(Calendar.MINUTE);
		firstDateOfMonth.set(Calendar.HOUR_OF_DAY, 0);
		firstDateOfMonth.set(Calendar.YEAR, year);
		firstDateOfMonth.set(Calendar.MONTH,month);
		firstDateOfMonth.set(Calendar.DAY_OF_MONTH, 1);
		
		Calendar startdate=(Calendar) firstDateOfMonth.clone();
		startdate.add(Calendar.DAY_OF_MONTH, Calendar.SUNDAY-startdate.get(Calendar.DAY_OF_WEEK));
		
		Calendar lastDateOfMonth=(Calendar) firstDateOfMonth.clone();
		lastDateOfMonth.set(Calendar.DAY_OF_MONTH,firstDateOfMonth.getActualMaximum(Calendar.DAY_OF_MONTH));
		
		Calendar lastDate=(Calendar) lastDateOfMonth.clone();
		lastDate.add(Calendar.DAY_OF_MONTH, Calendar.SATURDAY-lastDate.get(Calendar.DAY_OF_WEEK));
		returnMap.put("year_month value="+this.year+"_"+this.month,new HashMap());
		int holiday=0;
		while(!startdate.after(lastDate)){
			//查看该天是否有分享
			long startsharesize=this.eventService.countStartedShareEventsByDay(startdate, currentUser, contacttype);
			long endsharesize=this.eventService.countEndedShareEventsByDay(startdate, currentUser, contacttype);
			int isholiday=isSysHoliday(startdate.get(Calendar.YEAR), startdate.get(Calendar.MONTH), startdate.get(Calendar.DAY_OF_MONTH));
			int weeknum=startdate.get(Calendar.DAY_OF_WEEK);
			boolean isweekend=weeknum==1||weeknum==7?true:false;
			int isThisMonth=startdate.get(Calendar.MONTH)==this.month?1:0;
			
				
			Map<String,Object> temp2=new HashMap<String,Object>();
			temp2.put("isThisMonth", ""+isThisMonth);
			temp2.put("startsharesize", startsharesize);
			temp2.put("endsharesize", endsharesize);
			//temp2.put("alerteventsize", alertcount);
			temp2.put("weeknum", ""+startdate.get(Calendar.WEEK_OF_YEAR));
			temp2.put("weekofmonth", startdate.get(Calendar.WEEK_OF_MONTH));
			temp2.put("weekday", startdate.get(Calendar.DAY_OF_WEEK));
			temp2.put("lunartxt", Lunar.getLunarText(startdate));
			
			if(isweekend){
				if(isholiday==1||isholiday==-1){ //周末也是节日
					holiday=1;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}else{ //周末不休息
					holiday=0;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}
			}else{
				if(isholiday==1){ //平时但是节日
					holiday=1;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}else{ //平时也不是节日
					holiday=0;
					returnMap.put("month"+dateFormat.format(startdate.getTime())+" holiday="+holiday,temp2);
				}
			}
			startdate.add(Calendar.DAY_OF_MONTH, 1);
		}
		
		return returnMap;
	}
	
	public void getPrevYear(){
		Map<String,Object> jsonMap = new HashMap<String, Object>();
		Calendar calendar=Calendar.getInstance();
		calendar.clear(Calendar.MILLISECOND);
		calendar.clear(Calendar.SECOND);
		calendar.clear(Calendar.MINUTE);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.add(Calendar.YEAR, -1);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int maxday = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		int dayofmonth = calendar.get(Calendar.DAY_OF_MONTH);
		jsonMap.put("year", year);
		jsonMap.put("month", month);
		jsonMap.put("maxday", maxday);
		jsonMap.put("dayofmonth", dayofmonth);
		
		String jsonStr = JSONObject.fromObject(jsonMap).toString();
		Struts2Utils.renderText(jsonStr);
	}
	public void getNextYear(){
		Map<String,Object> jsonMap = new HashMap<String, Object>();
		Calendar calendar=Calendar.getInstance();
		calendar.clear(Calendar.MILLISECOND);
		calendar.clear(Calendar.SECOND);
		calendar.clear(Calendar.MINUTE);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.add(Calendar.YEAR, +1);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int maxday = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		int dayofmonth = calendar.get(Calendar.DAY_OF_MONTH);
		jsonMap.put("year", year);
		jsonMap.put("month", month);
		jsonMap.put("maxday", maxday);
		jsonMap.put("dayofmonth", dayofmonth);
		
		String jsonStr = JSONObject.fromObject(jsonMap).toString();
		Struts2Utils.renderText(jsonStr);
	}
	public void getPrevMonth(){
		Map<String,Object> jsonMap = new HashMap<String, Object>();
		Calendar calendar=Calendar.getInstance();
		calendar.clear(Calendar.MILLISECOND);
		calendar.clear(Calendar.SECOND);
		calendar.clear(Calendar.MINUTE);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.add(Calendar.MONTH, -1);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int maxday = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		int dayofmonth = calendar.get(Calendar.DAY_OF_MONTH);
		jsonMap.put("year", year);
		jsonMap.put("month", month);
		jsonMap.put("maxday", maxday);
		jsonMap.put("dayofmonth", dayofmonth);
		
		String jsonStr = JSONObject.fromObject(jsonMap).toString();
		Struts2Utils.renderText(jsonStr);
	}
	public void getNextMonth(){
		Map<String,Object> jsonMap = new HashMap<String, Object>();
		Calendar calendar=Calendar.getInstance();
		calendar.clear(Calendar.MILLISECOND);
		calendar.clear(Calendar.SECOND);
		calendar.clear(Calendar.MINUTE);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.add(Calendar.MONTH, +1);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int maxday = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		int dayofmonth = calendar.get(Calendar.DAY_OF_MONTH);
		jsonMap.put("year", year);
		jsonMap.put("month", month);
		jsonMap.put("maxday", maxday);
		jsonMap.put("dayofmonth", dayofmonth);
		
		String jsonStr = JSONObject.fromObject(jsonMap).toString();
		Struts2Utils.renderText(jsonStr);
	}
	public void getUserDefinedMonth(){
		Map<String,Object> jsonMap = new HashMap<String, Object>();
		Calendar calendar=Calendar.getInstance();
		calendar.clear(Calendar.MILLISECOND);
		calendar.clear(Calendar.SECOND);
		calendar.clear(Calendar.MINUTE);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int maxday = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		int dayofmonth = calendar.get(Calendar.DAY_OF_MONTH);
		jsonMap.put("year", year);
		jsonMap.put("month", month);
		jsonMap.put("maxday", maxday);
		jsonMap.put("dayofmonth", dayofmonth);
		
		String jsonStr = JSONObject.fromObject(jsonMap).toString();
		Struts2Utils.renderText(jsonStr);
	}
	public void getThisMonth(){
		Calendar calendar=Calendar.getInstance();
		Map<String,Object> jsonMap = new HashMap<String, Object>();
		jsonMap.put("year", calendar.get(Calendar.YEAR));
		jsonMap.put("month", calendar.get(Calendar.MONTH));
		jsonMap.put("maxday", calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		jsonMap.put("dayofmonth", calendar.get(Calendar.DAY_OF_MONTH));
		
		String jsonStr = JSONObject.fromObject(jsonMap).toString();
		Struts2Utils.renderText(jsonStr);
	}
	
	/**
	 * @param year 4位年数
	 * @param month 从0~11
	 * @param day 从1~31
	 * @return 0 周末上班  1休假 -1未找到
	 */
	private int isSysHoliday(int year, int month, int day) {
		return systemDateService.getSystemHolidayByDay(year, month, day);
	}


	private int year;
	private int month;
	private int date;
	private int contacttype; //0为全部 1为好友
	private String queryby;
	private String content;
	private String ids;
	private String querymycalendar;
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public int getMonth() {
		return month;
	}
	public void setMonth(int month) {
		this.month = month;
	}
	public int getDate() {
		return date;
	}
	public void setDate(int date) {
		this.date = date;
	}
	public int getContacttype() {
		return contacttype;
	}

	public void setContacttype(int contacttype) {
		this.contacttype = contacttype;
	}

	public String getQueryby() {
		return queryby;
	}

	public void setQueryby(String queryby) {
		this.queryby = queryby;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public String getQuerymycalendar() {
		return querymycalendar;
	}

	public void setQuerymycalendar(String querymycalendar) {
		this.querymycalendar = querymycalendar;
	}
	
}
